var game = {
    statLogin: function(callback) {
        var now = new Date();
        var zeroStamp = now.zeroTime().getStamp();
        var condition = {'mark.day': now.getDateNumber()};

        async.each(gServers.getSids(), function(sid, cb) {
            var db = gServers.getGameDB(sid);
            if (!db) {
                cb(); return;
            }
            
            var values = [];
            var cursor = db.collection('user').find(condition, {'_id':1, 'daily_vars.login_times':1});
            cursor.each(function(err, item) {
                if (cursor.isClosed()) {
                    if (values.length > 0) {
                        var sql = util.format("INSERT INTO login(`time`, `uid`, `sid`, `times`) VALUES%s;", values.join(','));
                        gStat.pool.query(sql, function(err) {
                            if (err) {
                                ERROR(util.format('game.statLogin sid=%d err=%j', sid, err));
                            }
                        });
                    }
                    cb(); return;
                }
                
                values.push(util.format("(%d, %d, %d, %d)", zeroStamp, item._id, sid, item.daily_vars.login_times));
            });
        }, function(err) {
            if (err) {
                resp.code = 1; resp.desc = err;
            }
            callback && callback();
        });
    },
}

exports.game = game;
